<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #fff;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

    .detail_con {
      padding: 1rem;
      padding-bottom: 3rem;
    }
    .detail_title h3 {
      font-size: 0.9rem;
      color: #333;
    }
    .detail_tit_sm h4 {
      font-size: 0.75rem;
      color: #333;
      font-weight: bold;
      line-height: 1.2rem;
    }
    .detail_addtime h6 {
      font-size: 0.6rem;
      color: #999;
      margin: 1rem 0;
    }
    .detail_text p {
      font-size: 0.75rem;
      line-height: 1.2rem;
      color: #333;
      margin: 1rem 0;
    }
    .detail_text p img {
      width: 100%;
    }
    .detail_like {
      text-align: center;
      border-top: 1px solid #f0f0f0;
      display: block;
      width: 100%;
      margin: 0 -1rem;
      padding: 0.5rem 1rem;
    }
    .detail_like img {
      width: 1rem;
      display: inline-block;
    }

    .ml_btns {
      position: fixed;
      bottom: 0;
      width: 100%;
    }
    .ml_btn {
      background: #f0f0f0;
      float: left;
      width: 100%;
      padding: 0.5rem 0;
      text-align: center;
      color: #666;
    }
    .ml_btn img {
      width: 1rem;
      display: inline-block;
      vertical-align: middle;
      margin-right: 0.25rem;
    }
    .ml_btn {
      background: #2997e4;
      color: #fff;
    }
	</style>
</head>
<body>
  <div id="app">
<div class="detail_con">
  <div class="detail_title">
    <h3>{{info.title}}</h3>
  </div>
  <div class="detail_addtime">
    <h6>{{info.createTime}}</h6>
  </div>
  <div class="detail_text">
    <div v-html="info.keywords"></div>
    <img src="info.pics" v-if="info.pics && info.pics !=''" alt="">
    <div v-html="info.content"></div>
  </div>
  <div class="detail_like">
    <span @click="likeClick()">
      <img src="../../image/focus.png" alt="" v-if="isLike">
      <img src="../../image/unfocus.png" alt="" v-else>
    </span>
    {{likeNum}}
  </div>
</div>
<div class="ml_btns">
  <div class="ml_btn">
    <img src="../../image/jr@3x.png" alt="">加入群聊
  </div>
</div>
</div>
</body>
<script type="text/javascript" src="../../script/api.js" ></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
apiready = function() {

  var app = new Vue({
    el: '#app',
    data: {
      id: 0,
      info: {},
      isLike: 0,
      likeNum: 0,
      token: 0,
      newsList: [],
    },
    created: function() {
      var $_this = this;
      $_this.id = api.pageParam.id
      $_this.token = $api.getStorage('token')

      api.ajax({
        url: window.Url.getPublishDetail + '2/' + $_this.id,
        timeout: 300,
      }, function(ret, err) {
          if (ret) {
              // api.alert({ msg: JSON.stringify(ret) });
              if (ret.data == null) return
              $_this.info = ret.data
          } else {
              api.alert({ msg: JSON.stringify(err) });
          }
      })
      $_this.likenumCount()
      $_this.isPaperLike()
    },
    methods: {
      likenumCount: function () {
        var $_this = this;
        api.ajax({
          url: window.Url.likenumCount + $_this.id,
          timeout: 300,
        }, function(ret, err) {
            if (ret) {
                // api.alert({ msg: JSON.stringify(ret) });
                $_this.likeNum = ret.data.likecount
            } else {
                api.alert({ msg: JSON.stringify(err) });
            }
        })
      },
      isPaperLike: function () {
        var $_this = this;
        api.ajax({
          url: window.Url.isPaperLike + $_this.id,
          timeout: 300,
          headers: {
            'baseParams': $_this.token //token
          },
        }, function(ret, err) {
            if (ret) {
                // api.alert({ msg: JSON.stringify(ret) });
                $_this.isLike = ret.data.islike
            } else {
                api.alert({ msg: JSON.stringify(err) });
            }
        })
      },
      addPaperLike: function () {
        var $_this = this;
        api.ajax({
          url: window.Url.addPaperLike,
          timeout: 300,
          method: 'post',
          headers: {
            'Content-Type': 'application/json',
            'baseParams': $_this.token //token
          },
          data: {
            body: {
              paper_id: $_this.id,
              type: 0
            }
          }
        }, function(ret, err) {
            if (ret) {
                // api.alert({ msg: JSON.stringify(ret) });

                $_this.likenumCount()
                $_this.isPaperLike()
            } else {
                api.alert({ msg: JSON.stringify(err) });
            }
        })
      },
      cancelPaperLike: function () {
        var $_this = this;
        api.ajax({
          url: window.Url.cancelPaperLike + '0/' + $_this.id,
          timeout: 300,
          headers: {
            'baseParams': $_this.token //token
          },
        }, function(ret, err) {
            if (ret) {
              // api.alert({ msg: JSON.stringify(ret) });
                        $_this.likenumCount()
                        $_this.isPaperLike()
            } else {
                api.alert({ msg: JSON.stringify(err) });
            }
        })

      },
      likeClick: function () {
        var $_this = this;
        if ($_this.isLike) {
          $_this.cancelPaperLike()
        } else {
          $_this.addPaperLike()
        }
      },
    }
  })
}
</script>
</html>
